package com.bolt.auth.security.admin.biz.sys.service;


import com.bolt.auth.admin.api.sys.entity.AreaEntity;
import com.bolt.auth.security.admin.biz.sys.repository.AreaRepository;
import com.bolt.support.base.service.BaseTreeService;
import com.bolt.support.spring.jpa.repository.BasicJpaRepository;
import com.bolt.support.ui.tree.vo.UITreeNode;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * Auto Generate Javadoc
 *
 * @author 日期:2018-02-07 16:11:28
 *         中国行政地区表
 **/
@Service
@Transactional(readOnly = true, rollbackFor = Exception.class)
public class AreaService extends BaseTreeService <AreaEntity, Long> {


    @Autowired
    private AreaRepository areaRepository;

    @Override
    protected BasicJpaRepository <AreaEntity, Long> getRepository() {
        return areaRepository;
    }

    public AreaEntity findByAreaCode(String code) {
        return areaRepository.findByAreaCode(code);
    }

    public List<AreaEntity> findByAreaCode(List<String> code){
       return  this.findAll((f)-> f.lambda().in(AreaEntity::getAreaCode,code).build());
    }

    @Override
    protected void converterTreeNode(AreaEntity entity, UITreeNode treeNode) {
        super.converterTreeNode(entity, treeNode);
        treeNode.setName(entity.getName());
        treeNode.put("areaCode",entity.getAreaCode());
    }
}
